package socket;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.WebClient;

public class MyVerticleHttps extends AbstractVerticle {

	@Override
	public void start() throws Exception {
//		System.setProperty("javax.net.ssl.trustStore", "C:\\Program Files\\Java\\jdk1.8.0_341\\jre\\lib\\security\\cacerts");
//		System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
//		WebClientOptions options = new WebClientOptions();
//		options.setDefaultHost("localhost");
//		options.setDefaultPort(8088);
//		options.setSsl(true);
//		options.setSslHandshakeTimeout(3);
//		options.setSslHandshakeTimeoutUnit(TimeUnit.SECONDS);
		WebClient client = WebClient.create(vertx);
		client.getAbs("https://127.0.0.1:8088/test/get/simple").ssl(true).send().onSuccess(
			r ->{
				JsonObject jsonObject = r.bodyAsJsonObject();
				System.out.println(jsonObject);
			}
		).onFailure(
				err -> {
					err.printStackTrace();
					System.out.println("Something went wrong " + err.getMessage());
				}
		);

//
//		client.get("/test/get2").addQueryParam("name","www").send( r ->{
//			if(r.succeeded()){
//				JsonObject jsonObject = r.result().bodyAsJsonObject();
//				System.out.println(jsonObject);
//			}
//		});
//
//		client.post("/test/param").addQueryParam("username","www").send( r ->{
//			if(r.succeeded()){
//				JsonObject jsonObject = r.result().bodyAsJsonObject();
//				System.out.println(jsonObject);
//			}
//		});
//
//		MultiMap form = MultiMap.caseInsensitiveMultiMap();
//		form.set("username", "Dale");
//		form.set("lastName", "Cooper");
//		client.post("/test/param").sendForm( form,r ->{
//			if(r.succeeded()){
//				JsonObject jsonObject = r.result().bodyAsJsonObject();
//				System.out.println(jsonObject);
//			}
//		});
//
//		User user = new User();
//		user.setId(111L);
//		user.setRealName("wwwwwwwwwwwwwwwwwww");
//		client.post("/test/body").sendJson( user, r ->{
//			if(r.succeeded()){
//				JsonObject jsonObject = r.result().bodyAsJsonObject();
//				System.out.println(jsonObject);
//			}
//		});

	}

	public static void main(String[] args) {
		Vertx vertx = Vertx.vertx();
		vertx.deployVerticle(new MyVerticleHttps());
	}
}
